package com.example.qxfw.nyqx.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.qxfw.common.entity.ny.CropDistIndex;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
@DS("service")
public interface CropDistIndexMapper extends BaseMapper<CropDistIndex> {
    @Select("select distinct cropname " +
            "from crop_dist_index ")
    List<String> getCropName();

    @Select("select cropname, diseasesname, starttime, endtime, easyhappentime, mintemp, maxtemp, temprange, minhumidity, maxhumidity, humidityrange, sunhour, defendmeasure " +
            "from crop_dist_index " +
            "where cropname='${cropName}' and '${time}' BETWEEN starttime AND to_char(endtime,'MMdd') ")
    List<CropDistIndex> selectListByCropName(String cropName, String time);

    @Select("select cropname, diseasesname, mintemp , maxtemp, minhumidity, maxhumidity, defendmeasure, starttime, to_char(endtime,'mm-dd') as endtime " +
            "from crop_dist_index " +
            "where cropname like '%${cropName}%' and ((starttime<to_char(endtime,'mmdd') and ('${time}' between starttime and to_char(endtime,'mmdd'))) or (starttime>to_char(endtime,'mm-dd') and ('${time}' not between starttime and to_char(endtime,'mmdd'))))")
    List<CropDistIndex> selectListLikeCropName(@Param("cropName")String cropName, @Param("time")String time);
}
